// miniprogram/pages/My_address/My_address.js
const db=wx.cloud.database()



Page({

  /**
   * 页面的初始数据
   */
  data: {
    activity_location:"",
    name:'',
    phone:'',
    AddAddress:true,
    seeAddress:false,
    
    remark:'',
    textcensus:0,
    max:200,
    show:false,
    
    address:"",
    subShow:false,
    
    
  },
  formsubmit:function(event){
    if(event.detail.value.name!==''&&event.detail.value.phone!==''){
      db.collection('My_address').add({
      data:{
        name:event.detail.value.name,
        phone:event.detail.value.phone, 
        remark:event.detail.value.activity_desc,
        address:this.data.activity_location
      }
    }).then(res=>{
      wx.showToast({
        title: '提交成功',
      })
      this.setData({
        show:false,
        AddAddress:false,
        seeAddress:true,
      })
    })
    }else{
      wx.showToast({
        title: '请填写完整信息',
        image:'../../images/title.png'
      })
    }
    
  },
  tj:function(event){
    let value=event.detail.value
    let len=parseInt(value.length)
    if(len>200)return;
    this.setData({
      textcensus:len
    })

  },
  bindMultiPickerChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      multiIndex: e.detail.value
    })
  },
 
  onshow:function(event){
    this.setData({
      subShow:true
    })

  },
  subClose:function(event){
    let that=this;
    that.setData({
      subShow:false,
      
      
    })

  },
  // van-popup
  onClose:function(){
    this.setData({
      show:false
    })

  },

  add:function(){
    this.setData({
      show:true
    })

  },

  getLocation: function () {
  
    wx.navigateTo({
      url: '../position/position',
    });
  },

 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    
    db.collection('shopping_car').where({
      box_checked:"true"
    }).get({
      success:function(res){
        
        that.setData({
          box:res.data           
        })
        // that.get_money_sum()
      },fail:function(res){
        console.log('获取商品失败',res)
      }
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    console.log(getApp().data.activity_location);//从position跳转过来，可以
    // console.log(this.data.address);
    location = getApp().data.activity_location;
    if (location != "") {
      that.setData({
        activity_location: location
        // activity_location: this.data.address//这个没用，可能onshow最先获取不到onLoad值
      });
    }
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})